import table from '@/components/dt/table/render.js'
import Opt from '@/components/dt/info/Opt.js'

let _this = null
let labelObj1 = {
  CLUETARGET: '线索',
  VISITOR: '来人'
}
class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    let setList = [
      {
        align: 'center',
        header: {
          requiredTxt: {
            title: `${labelObj1[_this.modalType]}目标(组)`
          }
        },
        slots: {
          default: ({ row }, h) => {
            return table.cell.input(_this, h, {
              key: 'clueTarget',
              data: row,
              placeholder: ' ',
              type: 'number',
              disabled: _this.isCheck,
              blur: () => {
                _this.targetChange(row.clueTarget)
              }
            })
          }
        }
      },
      {
        field: 'handles',
        title: '操作项',
        align: 'center',
        fixed: 'right',
        visible: !_this.isCheck,
        cell: (item) => {
          let btn = []
          btn.push({
            title: '无需设定',
            event: 'noSet'
          })
          return { btn }
        }
      }
    ]
    let adjustList = [
      {
        field: 'clueTarget',
        title: `初始${labelObj1[_this.modalType]}目标(组)`,
        align: 'center'
      },
      {
        field: 'adjustmentTarget',
        align: 'center',
        header: {
          requiredTxt: {
            title: `调整${labelObj1[_this.modalType]}目标(组)`
          }
        },
        slots: {
          default: ({ row }, h) => {
            return table.cell.input(_this, h, {
              key: 'adjustmentTarget',
              type: 'number',
              placeholder: ' ',
              disabled: _this.isCheck,
              data: row,
              blur: () => {
                _this.adjustChange(row.adjustmentTarget, row)
              }
            })
          }
        }
      },
      {
        field: 'diff',
        title: `调整差(组)`,
        align: 'center'
      },
      {
        field: 'handles',
        title: '操作项',
        align: 'center',
        fixed: 'right',
        cell: (item) => {
          let btn = []
          btn.push({
            title: `调整记录(${item.upNum})`,
            event: 'changeLog'
          })
          return { btn }
        }
      }
    ]

    if (_this.setGoalType == 'SET') {
      this.all = [...setList]
    } else {
      this.all = [...adjustList]
    }
  }
}

export default Column
